<template>
	<view class="banquet-info">
		<view class="c-row-box">
			<view class="c-row-head"><view class="c-row-title">宝宝宴</view></view>
			<view class="c-row-item">
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							执行公司
						</view>
						<view class="col-text">
							<picker mode="selector" :range="companyList" range-key="title" @change="companyChange" :disabled="isPreview">
								<view>{{ selectedCompany }}</view>
							</picker>
						</view>
					</view>
				</view>
				
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							派对时间
						</view>
						<view class="col-text">
							<picker mode="date" :disabled="isPreview" :start="startDate" :end="endDate" @change="partyDateChange">
								<view>{{ orderParams.event_date }}</view>
							</picker>
						</view>
					</view>
				</view>
				
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							签约日期
						</view>
						<view class="col-text">
							<picker mode="date" :disabled="isPreview" :start="startDate" :end="endDate" @change="signDateChange">
								<view>{{ orderParams.sign_date }}</view>
							</picker>
						</view>
					</view>
				</view>
				
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							客户姓名
						</view>
						<view class="col-text"><input type="text" v-model="orderParams.bridegroom" :disabled="isPreview" placeholder="请输入" /></view>
					</view>
				</view>
				
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							联系方式
						</view>
						<view class="col-text"><input type="number" maxlength="11" v-model="orderParams.bridegroom_mobile" :disabled="isPreview" placeholder="请输入" /></view>
					</view>
				</view>
				
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							派对桌数
						</view>
						<view class="col-text"><input type="digit" v-model="babyParams.table_amount" @input="babyChange" :disabled="isPreview" placeholder="请输入" /></view>
					</view>
				</view>
				
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							派对餐标
						</view>
						<view class="col-text"><input type="digit" v-model="babyParams.table_price" @input="babyChange" :disabled="isPreview" placeholder="请输入" /></view>
					</view>
				</view>
				
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">优惠金额</view>
						<view class="col-text"><input type="digit" v-model="babyParams.baby_discount" @input="babyChange" :disabled="isPreview" placeholder="请输入" /></view>
					</view>
				</view>
				
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							餐饮总价
						</view>
						<view class="col-text">
							<text>{{ babyParams.food_totals }}</text>
						</view>
					</view>
				</view>
				
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">布置费用</view>
						<view class="col-text"><input type="digit" v-model="babyParams.arrangement" @input="babyChange" :disabled="isPreview" placeholder="请输入" /></view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import dictionary from '@/utils/dictionary.js';

export default {
	props: {
		isPreview: {
			type: Boolean,
			default() {
				return false;
			}
		},
		babyParams: {
			type: Object,
			default() {
				return {};
			}
		},
		orderParams: {
			type: Object,
			default() {
				return {};
			}
		},
		order: {
			type: Object,
			default() {
				return {};
			}
		},
		
		startDate: {
			type: String,
			default() {
				return '';
			}
		},
		endDate: {
			type: String,
			default() {
				return '';
			}
		}
	},
	data() {
		return {};
	},
	computed: {
		companyList: function() {
			let companyList = dictionary.getPicker('companyList');
			companyList = companyList.filter(ele => ele.is_valid == 1);
			
			return companyList;
		},
		selectedCompany: function() {
			return dictionary.getPickerTitle('companyList', this.babyParams.company_id, '请选择');
		},
	},
	beforeMount() {
		this.dictionary = dictionary;
	},
	methods: {
		// 选择公司
		companyChange(e) {
			let index = e.target.value;
			this.babyParams.company_id = this.companyList[index].id;
		},

		// 派对时间
		partyDateChange(e) {
			this.orderParams.event_date = e.target.value;
		},
		
		signDateChange(e) {
			this.orderParams.sign_date = e.target.value;
		},

		// 信息发生变化
		babyChange() {
			let that = this;
			let table_amount = !that.babyParams.table_amount ? 0 : parseFloat(that.babyParams.table_amount);
			let table_price = !that.babyParams.table_price ? 0 : parseFloat(that.babyParams.table_price);
			let food_totals = table_amount * table_price;
			that.babyParams.food_totals = food_totals;
			
			// 布置费用
			let arrangement = !that.babyParams.arrangement ? 0 : parseFloat(that.babyParams.arrangement);
			let discount = !that.babyParams.baby_discount ? 0 : parseFloat(that.babyParams.baby_discount);
			
			// 宝宝宴总金额
			that.babyParams.baby_totals = (food_totals + arrangement - discount).toFixed(2);
			that.$emit('getOrderTotals');
		},

		// 选择酒店
		chooseSearch(type) {
			this.$emit('chooseSearch', type);
		}
	}
};
</script>

<style lang="less">
@import url('../../components/common.less');
@import url('../common/common.less');
</style>
